package main

import (
	"github.com/julienschmidt/httprouter"
	"net/http"
)

func main() {
	router := httprouter.New()
	router.GET("/default", func(writer http.ResponseWriter, request *http.Request, _ httprouter.Params) {
		writer.Write([]byte("this is a default view"))
	})
	router.POST("/default", func(writer http.ResponseWriter, request *http.Request, _ httprouter.Params) {
		writer.Write([]byte("this is a post request"))
	})
	// 精确匹配
	router.GET("/user/:name", func(writer http.ResponseWriter, request *http.Request, params httprouter.Params) {
		writer.Write([]byte("user name:" + params.ByName("name")))
	})
	// 匹配所有
	//router.GET("/user/*name", func(writer http.ResponseWriter, request *http.Request, params httprouter.Params) {
	//	writer.Write([]byte("user name:" + params.ByName("name")))
	//})

	http.ListenAndServe(":80", router)
}
